<%@ page contentType="text/html; charset=utf-8"%>
<%@ include file="../../../common/include.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>添加费用信息</title>
<jsp:include page="../../../common/head.jsp">
	  <jsp:param name="_useCalendar" value="true"/>
</jsp:include>
<script language="javascript">
	function saveData(submitType){
		var objarr = new Array(
			["feeDetail.areaId","地区","notEmpty",""],
			["feeDetail.areaDeptId","事业部","notEmpty",""],
			["feeDetail.financeSupervisorId","财务主管","notEmpty",""],
			["feeDetail.targetId","对象名称","notEmpty",""],
			["feeDetail.feeDate","费用日期","notEmpty",""],
			["feeDetail.feeTypeName","费用类型","notEmpty",""],
			["feeDetail.note1","费用标注1","max","String:50"],
			["feeDetail.note2","费用标注2","max","String:50"],
			["feeDetail.billAmount","票据金额","float","10.4"],
			["feeDetail.billCount","票据张数","int","3"],
			["feeDetail.certificateAmount","凭证金额","float","10.4"],
			["feeDetail.certificateCount","凭证张数","int","3"],
			["feeDetail.feeDetailRemark","备注","max","String:500"]
		);
		if(xj.CheckAll(objarr))
		{
			if(confirm("确认保存？"))
			{
				$("#submitType").val(submitType);
				document.getElementById("form1").submit();
			}
		}
	}

	//返回
	function goback()
	{
		window.top.close();
	}

	//将select的option的text放入hidden
	function selectOption(objSelect,hiddenId)
	{
		$("#"+hiddenId).val($(objSelect).find("option:selected").text());
		//地区变换变换费用类型
		if(hiddenId=="areaName")
		{
			selectFeeTarget();
		}
	}
	//选择费用类型
	function selectFeeType(){
		var code = ModalWindow("jump.do?path=listDictComm.do&toJsp=/jsp/common/code/lst_code_dict.jsp&kindId=004",640,480);
		if(code!=null)
		{
			var str = code.split("#");
			$("#feeTypeId").val(str[0]);
			$("#feeTypeName").val(str[1]);
		}
	}
	//查看同类费用明细
	function showDetail(){
		var url = "jump.do?path=listSameTypeFeeDetail.do&feeDetail.areaId="+$("#areaId").val()+
					"&feeDetail.areaDeptId="+$("#areaDeptId").val()+
					"&feeDetail.feeTypeId="+$("#feeTypeId").val()+
					"&feeDetail.feeTarget="+$("#feeTarget").val()+
					"&feeDetail.targetId="+$("#targetId").val()+
					"&feeDetail.note1="+$("#note1").val()+
					"&feeDetail.note2="+$("#note2").val();
		ModalWindow(url,0,0);
	}
	$.ready = function()
	{
		selectFeeTarget('${feeDetail.targetId}');
		$(".selectValueFilter").bind("keyup", function(){
			var selectObj = $(this).next();
			var val = $(this).val();
			$(selectObj).find("option").each(function(i){
				if($(this).text().indexOf(val)!=-1)
					$(this).attr("selected","selected");
			})
		});
	}
	//变换对象
	function selectFeeTarget(targetId)
	{
		var feeTarget = $("#feeTarget").find("option:selected").val();
		var areaId = $("#areaId").find("option:selected").val();
		var tmp = parseInt(Math.random()*1000000+1);
		if(feeTarget=="地区人员"&&areaId=="")
		{
			alert("请先选择地区！");
			$("#feeTarget").val("");
			return;
		}
		var url = "showFeeTargetFeeDetail.do?feeTarget="+feeTarget+"&areaId="+areaId+"&tmp="+tmp;
		
		$.get(url, {},function (data, textStatus){
			$("#targetId").html(data);
			if(targetId!=null)
			{
				$("#targetId").val(targetId);
			}
		});
	}
	<c:if test="${feeDetail.feeId ne null}">
		window.top.returnValue="ok";
	</c:if>
	function calAmount()
	{
		var billAmount = $("#billAmount").val();
		var certificateAmount = $("#certificateAmount").val();
		if(isNaN(billAmount)||billAmount=="")
			billAmount = 0;
		if(isNaN(certificateAmount)||certificateAmount=="")
			certificateAmount = 0;
		$("#sumAmount").val(parseFloat(billAmount)+parseFloat(certificateAmount));
	}
	function calBillCertificateCount()
	{
		var billCount = $("#billCount").val();
		var certificateCount = $("#certificateCount").val();
		if(isNaN(billCount)||billCount=="")
			billCount = 0;
		if(isNaN(certificateCount)||certificateCount=="")
			certificateCount = 0;
		
		$("#billCertificateCount").val(parseFloat(billCount)+parseFloat(certificateCount));
	}
	
</script>

</head>
<body>
<form name="form1" id="form1"  action="addFeeDetail.do" method="post">
	<input type="hidden" id="submitType" name="submitType" value="save"/>
	<input type="hidden" id="from" name="from" value="${param.from}"/>
	<input type="hidden" id="feeReportId" name="feeReportId" value="${param.feeReportId}"/>
	<c:if test="${param.from eq 'writtenOff'}">
		<c:set var="style" value="display:none;"></c:set>
	</c:if>
	<div id="body_div">
	<w:ShowTitle name="费用登记">
	<w:TitleButton funcName="保存并复制添加" onClickFunction="saveData('saveAndAdd')" urlImg="${ctx}/images/main/save.png"/>
	<w:TitleButton funcName="保存" onClickFunction="saveData('save')" urlImg="${ctx}/images/main/save.png"/>
	<w:TitleButton funcName="返回" onClickFunction="goback()" urlImg="${ctx}/images/main/back.png"/>
	</w:ShowTitle>
	<div id="body_content">
	<table width="100%">
            <tr>
              <td width="80" class="right_align">地区</td>
              <td width="230" class="left_align">
				<input type="hidden" id="areaName" name="feeDetail.areaName" value="${feeDetail.areaName}"/>
				<input type="text" class="selectValueFilter" style="${style}"/>
				<w:select name="feeDetail.areaId" styleId="areaId" value="${feeDetail.areaId}" onchange="selectOption(this,'areaName')" style="${style}">
					<w:option optionLabel="请选择" optionValue=""></w:option>
					<w:options options="${CodeDict}" optionLabel="codeName" optionValue="codeId" filterFieldName="parentCodeId" filterFieldValue="001"></w:options>
				</w:select>
				<c:if test="${param.from eq 'writtenOff'}">
					${feeDetail.areaName}
				</c:if>
			  </td>
              <td width="80" class="right_align"><span class="left_align">事业部</span></td>
              <td width="230" class="left_align">
				<input type="hidden" id="areaDeptName" name="feeDetail.areaDeptName" value="${feeDetail.areaDeptName}"/>
              	<input type="text" class="selectValueFilter" style="${style}"/>
              	<w:select name="feeDetail.areaDeptId" styleId="areaDeptId" value="${feeDetail.areaDeptId}" onchange="selectOption(this,'areaDeptName')" style="${style}">
					<w:option optionLabel="请选择" optionValue=""></w:option>
					<w:options options="${CodeDict}" optionLabel="codeName" optionValue="codeId" filterFieldName="parentCodeId" filterFieldValue="002"></w:options>
				</w:select>
				<c:if test="${param.from eq 'writtenOff'}">
					${feeDetail.areaDeptName}
				</c:if>
			  </td>
              <td class="right_align" width="80">财务主管</td>
              <td class="left_align">
              	<input type="hidden" id="financeSupervisorName" name="feeDetail.financeSupervisorName" value="${feeDetail.financeSupervisorName}"/>
				<input type="text" class="selectValueFilter"/>
				<w:select name="feeDetail.financeSupervisorId" styleId="financeSupervisorId" value="${feeDetail.financeSupervisorId}" onchange="selectOption(this,'financeSupervisorName')">
					<w:option optionLabel="请选择" optionValue=""></w:option>
					<w:options options="${userList}" optionLabel="userName" optionValue="userId"></w:options>
				</w:select>
              </td>
            </tr>
            <tr>
              <td class="right_align">发生对象</td>
              <td class="left_align">
              	<w:select name="feeDetail.feeTarget" styleId="feeTarget" value="${feeDetail.feeTarget}" onchange="selectFeeTarget()">
					<w:option optionLabel="请选择" optionValue=""></w:option>
					<w:option optionLabel="地区人员" optionValue="地区人员"></w:option>
					<w:option optionLabel="地区办事处" optionValue="地区办事处"></w:option>
					<w:option optionLabel="销售分线" optionValue="销售分线"></w:option>
				</w:select>
              </td>
              <td class="right_align">对象名称
              </td>
              <td class="left_align" id="targetIdTd">
              	<input type="hidden" id="targetName" name="feeDetail.targetName" value="${feeDetail.targetName}"/>
              	<input type="text" class="selectValueFilter"/>
              	<select name="feeDetail.targetId" id="targetId" onchange="selectOption(this,'targetName')"></select>
              </td>
              <td class="right_align">费用日期</td>
              <td class="left_align">
				<input type="text" name="feeDetail.feeDate" value="<fmt:formatDate value='${feeDetail.feeDate}' pattern='yyyy-MM-dd' />" onfocus="new WdatePicker()" readonly="readonly" class="inputCal"/>
              </td>
            </tr>
            <tr>
              <td class="right_align">费用类别</td>
              <td class="left_align">
              	<input type="hidden" id="feeTypeId" name="feeDetail.feeTypeId" value="${feeDetail.feeTypeId}"/>
              	<input type="text" name="feeDetail.feeTypeName" id="feeTypeName" class="inputQry" readonly="readonly" onclick="selectFeeType()" value="${feeDetail.feeTypeName}"/>
              	<input type="button" value="明细" onclick="showDetail()" style="width:40px;"/>
              </td>
              <td class="right_align">费用标注1</td>
              <td class="left_align"><input type="text" name="feeDetail.note1" id="note1" value="${feeDetail.note1}"/></td>
              <td class="right_align">费用标注2</td>
              <td class="left_align"><input type="text" name="feeDetail.note2" id="note2" value="${feeDetail.note2}"/></td>
            </tr>
            <tr>
              <td class="right_align">票据金额</td>
              <td class="left_align"><input type="text" name="feeDetail.billAmount" id="billAmount" onblur="calAmount()"/></td>
              <td class="right_align">票据张数</td>
              <td class="left_align"><input type="text" name="feeDetail.billCount" id="billCount" onblur="calBillCertificateCount()"/></td>
              <td class="right_align"></td>
              <td class="left_align"></td>
            </tr>
            <tr>
              <td class="right_align">凭证金额</td>
              <td class="left_align"><input type="text" name="feeDetail.certificateAmount" id="certificateAmount" onblur="calAmount()"/></td>
              <td class="right_align">凭证张数</td>
              <td class="left_align"><input type="text" name="feeDetail.certificateCount" id="certificateCount" onblur="calBillCertificateCount()"/></td>
              <td class="right_align">登记日期</td>
              <td class="left_align"><input type="text" name="feeDetail.createDate" value="${wfn:getDateTime("yyyy-MM-dd")}" onfocus="new WdatePicker()" readonly="readonly" class="inputCal"/></td>
            </tr>
            <tr>
              <td class="right_align">金额合计</td>
              <td class="left_align"><input type="text" name="sumAmount"  id="sumAmount"/></td>
              <td class="right_align">张数合计</td>
              <td class="left_align"><input type="text" name="billCertificateCount" id="billCertificateCount"/></td>
              <td class="right_align"></td>
              <td class="left_align"></td>
            </tr>
            <tr>
              <td class="right_align">备注</td>
              <td colspan="5" class="left_align">
              	<textarea rows="5" cols="80" name="feeDetail.feeDetailRemark">${feeDetail.feeDetailRemark}</textarea>
              </td>
            </tr>
           	<c:if test="${feeDetail.feeId ne null}">
            <tr>
              <td colspan="6" class="left_align warnText">
              	数据保存成功，您可以利用以上数据继续填报！
              </td>
            </tr>
           	</c:if>
          </table>
	</div>
	</div>	
</form>
</body>
</html> 